home *** CD-ROM | disk | FTP | other *** search
/ Computer Music Interactif…cial Edition 1999 Winter / cd 3.iso / mac / Mac / Shares / Midishare™1.68 / Development Tools / Common Lisp / MCL_68k / MidiShare.lisp next >
Encoding:
Text File  |  1996-09-09  |  24.6 KB  |  742 lines  |  [TEXT/CCL2]

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;  MidiShare.lisp
  3. ;;
  4. ;;  Copyright (c) 1993, GRAME.  All rights reserved.
  5. ;;
  6. ;;  Common Lisp interface to MidiShare 1.68.
  7. ;;
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9.  
  10.  
  11. ;;====================================================================================
  12. ;; Définition du package, importations et exportations
  13. ;;------------------------------------------------------------------------------------
  14.  
  15. (defpackage "MIDISHARE" 
  16.   (:use "COMMON-LISP" "CCL"))
  17.   
  18. (in-package :midishare)
  19.  
  20. (eval-when (:compile-toplevel :load-toplevel :execute)
  21.   (let ((*warn-if-redefine* nil))
  22.     (require :ff)))
  23.   
  24.  
  25. (export '(typeNote typeKeyOn typeKeyOff typeKeyPress typeCtrlChange typeProgChange 
  26.           typeChanPress typePitchWheel typeSongPos typeSongSel typeClock typeStart
  27.           typeContinue typeStop typeTune typeActiveSens typeReset typeSysEx typeStream
  28.           typePrivate typeProcess typeDProcess typeQFrame typeReserved typeDead
  29.           typeCtrl14b typeNonRegParam typeRegParam typeSeqNum typeText typeCopyright 
  30.           typeSeqName typeInstrName typeLyric typeMarker typeCuePoint typeChanPrefix 
  31.           typeEndTrack typeTempo typeSMPTEOffset typeTimeSign typeKeySign typeSpecific
  32.           
  33.           MIDIerrSpace MIDIerrRefNum MIDIerrBadType MIDIerrIndex
  34.           
  35.           ModemPort PrinterPort
  36.           
  37.           MidiExternalSync MidiSyncAnyPort 
  38.           Smpte24Fr Smpte25Fr Smpte30DF Smpte30Fr
  39.           
  40.           MIDIOpenAppl MIDICloseAppl MIDIChgName MIDIChgConnect MIDIOpenModem MIDICloseModem
  41.           MIDIOpenPrinter MIDIClosePrinter MIDISyncStart MIDISyncStop MIDIChangeSync
  42.           
  43.           MidiGetVersion MidiCountAppls MidiGetIndAppl MidiGetNamedAppl MidiOpen MidiClose
  44.           MidiGetName MidiSetName MidiGetInfo MidiSetInfo MidiGetFilter MidiSetFilter
  45.           MidiGetRcvAlarm MidiSetRcvAlarm MidiGetApplAlarm MidiSetApplAlarm MidiConnect
  46.           MidiIsConnected MidiGetPortState MidiSetPortState MidiFreeSpace MidiNewEv MidiCopyEv
  47.           MidiFreeEv MidiSetField MidiGetField MidiAddField MidiCountFields MidiNewSeq
  48.           MidiAddSeq MidiFreeSeq MidiClearSeq MidiApplySeq MidiGetTime MidiSendIm MidiSend
  49.           MidiSendAt MidiCountEvs MidiGetEv MidiAvailEv MidiFlushEvs MidiReadSync MidiWriteSync
  50.           MidiCall MidiTask MidiDTask MidiForgetTask MidiCountDTasks MidiFlushDTasks MidiExec1DTask
  51.           MidiNewCell MidiFreeCell MidiTotalSpace MidiGrowSpace MidiShare
  52.  
  53.           link date type ref port chan xfield pitch vel dur xfields text 
  54.           firstEv lastEv FilterBit 
  55.           AcceptPort AcceptType AcceptChan))
  56.  
  57. (use-package 'midishare 'cl-user)
  58.  
  59. ;;====================================================================================
  60.  
  61.  
  62.  
  63. ;; Some useful tools
  64. ;;-------------------
  65.  
  66. (defun %%get-string (ps) 
  67.   "Same as %get-string but work with mac non-zone pointers"
  68.   (let (name count)
  69.     (setq count (%get-byte ps))
  70.     (setq name (make-string count))  
  71.     (dotimes (i count)
  72.       (setq ps (%inc-ptr ps 1))
  73.       (setf (aref name i) (coerce (%get-byte ps) 'character)))
  74.     name))
  75.  
  76.  
  77.  
  78. ;; Records definitions (from MPW C MidiShare.h)
  79. ;;----------------------------------------------
  80.  
  81. ;; Extension record for typeSysEx events
  82.  
  83. (defrecord TMidiSEX  
  84.   (link (:pointer TMidiSEX))
  85.   (data (:array :byte 12)))
  86.  
  87. ;; Extension record for typePrivate, typeProcess and typeDProcess events
  88.  
  89. (defrecord TMidiST
  90.   (ptr1 :pointer)
  91.   (ptr2 :pointer)
  92.   (ptr3 :pointer)
  93.   (ptr4 :pointer))
  94.  
  95. ;; Record for every MidiShare event
  96.  
  97. (defrecord TMidiEv
  98.   (link (:pointer TMidiEv))
  99.   (date :longint)
  100.   (evtype :byte)
  101.   (ref :byte)
  102.   (port :byte)
  103.   (chan :byte)
  104.   (variant ((pitch :byte)
  105.             (vel :byte)
  106.             (dur :integer))
  107.            ((data0 :byte)
  108.             (data1 :byte)
  109.             (data2 :byte)
  110.             (data3 :byte))
  111.            ((info :longint))
  112.            ((linkSE (:pointer TMidiSEX)))
  113.            ((linkST (:pointer TMidiST)))))
  114.  
  115.  
  116. ;; Sequence header
  117.  
  118. (defrecord TMidiSeq
  119.   (first (:pointer TMidiEv))    ; first event
  120.   (last (:pointer TMidiEv))     ; last event
  121.   (undef1 :pointer)   
  122.   (undef2 :pointer) )  
  123.  
  124. ;; Record for an input filter
  125.  
  126. (defrecord TFilter
  127.   (port (string 63))     ; 256-bits
  128.   (evType (string 63))   ; 256-bits
  129.   (channel (string 1))   ;  16-bits
  130.   (unused (string 1)))   ;  16-bits
  131.  
  132. ;; Record for synchronisation informations
  133.  
  134. (defrecord TSyncInfo
  135.   (time :longint)
  136.   (reenter :longint)
  137.   (syncMode :unsigned-short)
  138.   (syncLocked :byte)
  139.   (syncPort :byte)
  140.   (syncStart :longint)
  141.   (syncStop :longint)
  142.   (syncOffset :longint)
  143.   (syncSpeed :longint)
  144.   (syncBreaks :longint)
  145.   (syncFormat :short))
  146.  
  147. ;; Record for smpte locations
  148.  
  149. (defrecord TSmpteLocation
  150.   (format :short)
  151.   (hours :short)
  152.   (minutes :short)
  153.   (seconds :short)
  154.   (frames :short)
  155.   (fracs :short))
  156.  
  157.  
  158. ;; Task Handle (for midiforgettask)
  159.  
  160. (defrecord TTaskHdl
  161.   (task (:pointer TMidiEv)) )
  162.  
  163. (defvar *taskhdl* (make-record :TTaskHdl))
  164.  
  165.  
  166. ;; Set *midiShare* with the address of MidiShare Entry Point (address stored at boot time into low memory address $B8)
  167.  
  168. (defvar *midiShare* (%get-ptr (%int-to-ptr #xB8)) "MidiShare entry point")
  169.  
  170.  
  171. ;; Constant definition for every type of MidiShare events
  172.  
  173. (defconstant typeNote 0          "a note with pitch, velocity and duration")
  174. (defconstant typeKeyOn 1         "a key on with pitch and velocity")
  175. (defconstant typeKeyOff 2        "a key off with pitch and velocity")
  176. (defconstant typeKeyPress 3      "a key pressure with pitch and pressure value")
  177. (defconstant typeCtrlChange 4    "a control change with control number and control value")
  178. (defconstant typeProgChange 5    "a program change with program number")
  179. (defconstant typeChanPress 6     "a channel pressure with pressure value")
  180. (defconstant typePitchWheel 7    "a pitch bender with lsb and msb of the 14-bit value")
  181. (defconstant typePitchBend 7     "a pitch bender with lsb and msb of the 14-bit value")
  182. (defconstant typeSongPos 8       "a song position with lsb and msb of the 14-bit position")
  183. (defconstant typeSongSel 9       "a song selection with a song number")
  184. (defconstant typeClock 10        "a clock request (no argument)")
  185. (defconstant typeStart 11        "a start request (no argument)")
  186. (defconstant typeContinue 12     "a continue request (no argument)")
  187. (defconstant typeStop 13         "a stop request (no argument)")
  188. (defconstant typeTune 14         "a tune request (no argument)")
  189. (defconstant typeActiveSens 15   "an active sensing code (no argument)")
  190. (defconstant typeReset 16        "a reset request (no argument)")
  191. (defconstant typeSysEx 17        "a system exclusive with any number of data bytes. Leading $F0 and tailing $F7 are automatically supplied by MidiShare and MUST NOT be included by the user")
  192. (defconstant typeStream 18       "a special event with any number of data and status bytes sended without any processing")
  193. (defconstant typePrivate 19      "a private event for internal use with 4 32-bits arguments")
  194. (defconstant typeProcess 128     "an interrupt level task with a function adress and 3 32-bits arguments")
  195. (defconstant typeDProcess 129    "a foreground level task with a function adress and 3 32-bits arguments")
  196. (defconstant typeQFrame 130      "a quarter frame message with a type from 0 to 7 and a value")
  197.  
  198.  
  199. (defconstant typeCtrl14b    131)
  200. (defconstant typeNonRegParam    132)
  201. (defconstant typeRegParam    133)
  202.  
  203. (defconstant typeSeqNum        134)
  204. (defconstant typeText        135)
  205. (defconstant typeCopyright    136)
  206. (defconstant typeSeqName    137)
  207. (defconstant typeInstrName    138)
  208. (defconstant typeLyric        139)
  209. (defconstant typeMarker        140)
  210. (defconstant typeCuePoint    141)
  211. (defconstant typeChanPrefix    142)
  212. (defconstant typeEndTrack    143)
  213. (defconstant typeTempo        144)
  214. (defconstant typeSMPTEOffset    145)
  215.  
  216. (defconstant typeTimeSign    146)
  217. (defconstant typeKeySign    147)
  218. (defconstant typeSpecific    148)
  219.  
  220. (defconstant typeReserved 149    "events reserved for futur use")
  221. (defconstant typedead 255        "a dead task. Used by MidiShare to forget and inactivate typeProcess and typeDProcess tasks")
  222.  
  223.  
  224. ;; Constant definition for every MidiShare error code
  225.  
  226. (defconstant MIDIerrSpace -1     "too many applications")
  227. (defconstant MIDIerrRefNum -2     "bad reference number")
  228. (defconstant MIDIerrBadType -3   "bad event type")
  229. (defconstant MIDIerrIndex -4     "bad index")
  230.  
  231.  
  232. ;; Constant definition for the Macintosh serial ports
  233.  
  234. (defconstant ModemPort 0     "Macintosh modem port")
  235. (defconstant PrinterPort 1     "Macintosh printer port")
  236.  
  237.  
  238. ;; Constant definition for the synchronisation modes
  239.  
  240. (defconstant MidiExternalSync #x8000     "Bit-15 set for external synchronisation")
  241. (defconstant MidiSyncAnyPort #x4000     "Bit-14 set for synchronisation on any port")
  242.  
  243.  
  244. ;; Constant definition for SMPTE formats
  245.  
  246. (defconstant Smpte24Fr 0     "24 frames per second SMPTE format")
  247. (defconstant Smpte25Fr 1     "25 frames per second SMPTE format")
  248. (defconstant Smpte30DF 2     "29.97 drop frame frames per second SMPTE format")
  249. (defconstant Smpte30Fr 3     "30 frames per second SMPTE format")
  250.  
  251.  
  252. ;; Constant definition for MidiShare world changes
  253.  
  254. (defconstant MIDIOpenAppl 1      "an application was opened")
  255. (defconstant MIDICloseAppl 2     "an application was closed")
  256. (defconstant MIDIChgName 3       "an application name was changed")
  257. (defconstant MIDIChgConnect 4    "a connection was changed")
  258. (defconstant MIDIOpenModem 5     "Modem port was opened")
  259. (defconstant MIDICloseModem 6    "Modem port was closed")
  260. (defconstant MIDIOpenPrinter 7   "Printer port was opened")
  261. (defconstant MIDIClosePrinter 8  "Printer port was closed")
  262. (defconstant MIDISyncStart 9     "SMPTE synchronisation just start")
  263. (defconstant MIDISyncStop 10     "SMPTE synchronisation just stop")
  264. (defconstant MIDIChangeSync 11   "the synchronisation mode was changed")
  265.  
  266.  
  267. ;;                        Usefull macros to access MidiShare data structures and events
  268. ;;========================================================================================
  269.  
  270. ;; Macros to access MidiShare events fields
  271. ;;-----------------------------------------
  272.  
  273.  
  274. ;; access to common fields
  275.  
  276. (defmacro link (e &optional (d nil d?))
  277. "read or set the link of an event"
  278.   (if d?
  279.     `(rset ,e :TMidiEv.link ,d)
  280.     `(rref ,e :TMidiEv.link)))
  281.  
  282. (defmacro date (e &optional d)
  283. "read or set the date of an event"
  284.   (if d
  285.     `(rset ,e :TMidiEv.date ,d)
  286.     `(rref ,e :TMidiEv.date)))
  287.  
  288. (defmacro type (e &optional v)
  289. "read or set the type of an event. Be careful in 
  290.  modifying the type of an event"
  291.   (if v
  292.     `(rset ,e :TMidiEv.evType ,v)
  293.     `(rref ,e :TMidiEv.evType)))
  294.  
  295. (defmacro ref (e &optional v)
  296. "read or set the reference number of an event"
  297.   (if v
  298.     `(rset ,e :TMidiEv.ref ,v)
  299.     `(rref ,e :TMidiEv.ref)))
  300.  
  301. (defmacro port (e &optional v)
  302. "read or set the port number of an event"
  303.   (if v
  304.     `(rset ,e :TMidiEv.port ,v)
  305.     `(rref ,e :TMidiEv.port)))
  306.  
  307. (defmacro chan (e &optional v)
  308. "read or set the chan number of an event"
  309.   (if v
  310.     `(rset ,e :TMidiEv.chan ,v)
  311.     `(rref ,e :TMidiEv.chan)))
  312.  
  313.  
  314. ;; fast access to extension fields for note, keyon and keyoff events
  315.  
  316. (defmacro pitch (e &optional v)
  317. "read or set the pitch of an event (equivalent to field 0)"
  318.   (if v
  319.     `(rset ,e :TMidiEv.pitch ,v)
  320.     `(rref ,e :TMidiEv.pitch)))
  321.  
  322. (defmacro vel (e &optional v)
  323. "read or set the velocity of an event (equivalent to field 1)"
  324.   (if v
  325.     `(rset ,e :TMidiEv.vel ,v)
  326.     `(rref ,e :TMidiEv.vel)))
  327.  
  328. (defmacro dur (e &optional v)
  329. "read or set the duration of an event (equivalent to field 0)"
  330.   (if v
  331.     `(rset ,e :TMidiEv.dur ,v)
  332.     `(rref ,e :TMidiEv.dur)))
  333.  
  334.  
  335.  
  336. ;; access to extension fields
  337.  
  338. (defmacro xfield (e &optional f v)
  339. "give the number of fields or read or set a particular field of an event"
  340.   (if f
  341.     (if v
  342.       `(midiSetField ,e ,f ,v)
  343.       `(midiGetField ,e ,f))
  344.     `(midiCountFields ,e)))
  345.  
  346.  
  347. ;; access to field list for sysex and other variable length events
  348.  
  349. (defmacro xfields (e &optional v)
  350.   (if v
  351.     `(let ((e ,e)) (mapc #'(lambda (f) (midiaddfield e f)) ,v))
  352.     `(let (l (e ,e))  (dotimes (i (midicountfields e)) (push (midigetfield e i) l)) (nreverse l)) ))
  353.  
  354.  
  355. ;; access to field list as strings (for text events)
  356.  
  357. (defmacro text (e &optional s)
  358.   (if s
  359.     `(xfields ,e (map 'list #'char-code ,s))
  360.     `(map 'string #'character (xfields ,e)) ))
  361.  
  362.  
  363.  
  364. ;; Macros to access MidiShare sequences first and last event
  365. ;;----------------------------------------------------------
  366.  
  367.  
  368. (defmacro firstEv (s &optional (e nil e?))
  369. "read or set the first event of a sequence"
  370.   (if e?
  371.     `(rset ,s :TMidiSeq.first ,e)
  372.     `(rref ,s :TMidiSeq.first)))
  373.  
  374. (defmacro lastEv (s &optional (e nil e?))
  375. "read or set the last event of a sequence"
  376.   (if e?
  377.     `(rset ,s :TMidiSeq.last ,e)
  378.     `(rref ,s :TMidiSeq.last)))
  379.  
  380.  
  381.  
  382. ;; Macros to access input filters
  383. ;;-----------------------------------------
  384.  
  385.  
  386. (defun FilterBit (p n &optional (val nil val?))
  387.   (if val?
  388.     (%put-byte p (if val 
  389.                    (logior (%get-byte p (ash n -3)) (ash 1 (logand n 7)))
  390.                    (logandc2 (%get-byte p (ash n -3)) (ash 1 (logand n 7))) )
  391.                (ash n -3))
  392.     (logbitp (logand n 7) (%get-byte p (ash n -3)))))
  393.  
  394. (defmacro AcceptPort (f p &rest s)
  395.   `(filterBit ,f ,p ,@s))
  396.  
  397. (defmacro AcceptType (f p &rest s)
  398.   `(filterBit (%inc-ptr ,f 32) ,p ,@s))
  399.  
  400. (defmacro AcceptChan (f p &rest s)
  401.   `(filterBit (%inc-ptr ,f 64) ,p ,@s))
  402.  
  403.  
  404.  
  405. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  406. ;;                       -- MidiShare calls --
  407. ;;
  408. ;; Interface description for a Pascal PROCEDURE 
  409. ;; with a word and a pointer parameter
  410. ;;  (ff-call *midiShare* :word <arg1> :ptr <arg2> :d0 <routine#>)
  411. ;;
  412. ;; Interface description for a Pascal FUNCTION 
  413. ;; with a word and a pointer parameter and a word result
  414. ;;  (ff-call *midiShare* :word 0 :word <arg1> :ptr <arg2> :d0 <routine#> :word)
  415. ;;
  416. ;; Interface description for a Pascal FUNCTION 
  417. ;; with a word and a pointer parameter and a pointer result
  418. ;;  (ff-call *midiShare* :ptr (%null-ptr) :word <arg1> :ptr <arg2> :d0 <routine#> :ptr)
  419. ;;
  420.  
  421. ;; General informations about MidiShare
  422.  
  423. (defun MidiShare ()
  424. "Test if MidiShare is intalled"
  425.   (and (= (%get-word *midiShare*) #xD080)
  426.        (= (%get-word *midiShare* 2) #xD080)))
  427.  
  428. (defmacro MidiGetVersion ()
  429. "Give MidiShare version as a fixnum. For example 168 as result means : version 1.68"
  430.   `(block nil (ff-call *midiShare* :word 0 :d0 0 :word)))
  431.  
  432.  
  433. ;; Informations about currently registred MidiShare client application
  434.  
  435. (defmacro MidiCountAppls ()
  436. "Give the number of registered MidiShare client applications"
  437.   `(block nil (ff-call *midiShare* :word 0 :d0 1 :word)))
  438.  
  439. (defmacro MidiGetIndAppl (index)
  440. "Give the reference number of a MidiShare application from its index, a fixnum
  441.  between 1 and (MidiCountAppls)"
  442.   `(block nil (ff-call *midiShare* :word 0 :word ,index :d0 2 :word)))
  443.  
  444. (defmacro MidiGetNamedAppl (name)
  445. "Give the reference number of a MidiShare application from its name"
  446.   `(with-pstrs ((s ,name))
  447.     (ff-call *midiShare* :word 0 :ptr s :d0 3 :word)))
  448.  
  449.  
  450. ;; To register a new MidiShare client application
  451.  
  452. (defmacro MidiOpen (name)
  453. "Open a new MidiShare client application with name name. Give a unique reference number."
  454.   `(with-pstrs ((s ,name))
  455.     (ff-call *midiShare* :word 0 :ptr s :d0 4 :word)))
  456.  
  457. (defmacro MidiClose (refNum)
  458. "Close an opened MidiShare application from its reference number"
  459.   `(block nil (ff-call *midiShare* :word ,refNum :d0 5)))
  460.  
  461.  
  462. ;; To access global informations about a client applications
  463.  
  464. (defmacro MidiGetName (refNum)
  465. "Give the name of a MidiShare application from its reference number"
  466.     `(block nil (%%get-string (ff-call *midiShare* :ptr (%null-ptr) :word ,refNum :d0 6 :ptr))))
  467.  
  468. (defmacro MidiSetName (refNum name)
  469. "Change the name of a MidiShare application"
  470.   `(with-pstrs ((s ,name))
  471.     (ff-call *midiShare* :word ,refNum :ptr s :d0 7 )))
  472.  
  473. (defmacro MidiGetInfo (refNum)
  474. "Give the 32-bits user defined content of the info field of a MidiShare application. 
  475.  Analogous to window's refcon."
  476.   `(block nil (ff-call *midiShare* :ptr (%null-ptr) :word ,refNum :d0 8 :ptr)))
  477.  
  478. (defmacro MidiSetInfo (refNum p)
  479. "Set the 32-bits user defined content of the info field of a MidiShare application. 
  480.  Analogous to window's refcon."
  481.   `(block nil (ff-call *midiShare* :word ,refNum :ptr ,p :d0 9)))
  482.  
  483. (defmacro MidiGetFilter (refNum)
  484. "Give a pointer to the input filter record of a MidiShare application. 
  485.  Give NIL if no filter is installed"
  486.   `(block nil (ff-call *midiShare* :ptr (%null-ptr) :word ,refNum :d0 10 :ptr)))
  487.  
  488. (defmacro MidiSetFilter (refNum p)
  489. "Install an input filter. The argument p is a pointer to a filter record."
  490.   `(block nil (ff-call *midiShare* :word ,refNum :ptr ,p :d0 11)))
  491.  
  492.  
  493. ;; To install real-time alarms (must be C functions)
  494.  
  495. (defmacro MidiGetRcvAlarm (refNum)
  496. "Get the adress of the receive alarm"
  497.   `(block nil (ff-call *midiShare* :ptr (%null-ptr) :word ,refNum :d0 #x0C :ptr)))
  498.  
  499. (defmacro MidiSetRcvAlarm (refNum alarm)
  500. "Install a receive alarm"
  501.   `(block nil (ff-call *midiShare* :word ,refNum :ptr ,alarm :d0 #x0D)))
  502.  
  503. (defmacro MidiGetApplAlarm (refNum)
  504. "Get the adress of the context alarm"
  505.   `(block nil (ff-call *midiShare* :ptr (%null-ptr) :word ,refNum :d0 #x0E :ptr)))
  506.  
  507. (defmacro MidiSetApplAlarm (refNum alarm)
  508. "Install a context alarm"
  509.   `(block nil (ff-call *midiShare* :word ,refNum :ptr ,alarm :d0 #x0F)))
  510.  
  511.  
  512. ;; To connect client applications
  513.  
  514. (defmacro MidiConnect (src dst state)
  515. "Connect or disconnect two MidiShare applications"
  516.   `(block nil (ff-call *midiShare* :word ,src :word ,dst :word (if ,state -1 0) :d0 #x10)))
  517.  
  518. (defmacro MidiIsConnected (src dst)
  519. "Test if two MidiShare applications are connected"
  520.   `(not (eq 0 (block nil (ff-call *midiShare* :word 0 :word ,src :word ,dst :d0 #x11 :word)))))
  521.  
  522.  
  523. ;; To open and close the mac physical ports
  524.  
  525. (defmacro MidiGetPortState (port)
  526. "Give the state : open or closed, of a MidiPort"
  527.   `(not (eq 0 (block nil (ff-call *midiShare* :word 0 :word ,port :d0 #x12 :word)))))
  528.  
  529. (defmacro MidiSetPortState (port state)
  530. "Open or close a MidiPort"
  531.   `(block nil (ff-call *midiShare* :word ,port :word (if ,state -1 0) :d0 #x13)))
  532.  
  533.  
  534. ;; To create, copy and free MidiShare events
  535.  
  536. (defmacro MidiNewEv (typeNum)
  537. "Allocate a new MidiEvent"
  538.   `(block nil (ff-call *midiShare* :ptr (%null-ptr) :word ,typeNum :d0 #x15 :ptr)))
  539.  
  540. (defmacro MidiCopyEv (ev)
  541. "Duplicate a MidiEvent"
  542.   `(block nil (ff-call *midiShare* :ptr (%null-ptr) :ptr ,ev :d0 #x16 :ptr)))
  543.  
  544. (defmacro MidiFreeEv (ev)
  545. "Free a MidiEvent"
  546.   `(block nil (ff-call *midiShare* :ptr ,ev :d0 #x17)))
  547.  
  548.  
  549. ;; To know about memory space available for MidiShare events
  550.  
  551. (defmacro MidiFreeSpace ()
  552. "Amount of free MidiShare cells"
  553.   `(block nil (ff-call *midiShare* :long 0 :d0 #x14 :long)))
  554.  
  555. (defmacro MidiTotalSpace ()
  556. "Total amount of Cells"
  557.   `(block nil (ff-call *midiShare* :long 0 :d0 #x35 :long)))
  558.  
  559. (defmacro MidiGrowSpace (n)
  560. "Total amount of Cells"
  561.   `(block nil (ff-call *midiShare* :long 0 :long ,n :d0 #x36 :long)))
  562.  
  563.  
  564. ;; To access information fields of MidiShare events
  565.  
  566. (defmacro MidiSetField (ev field val)
  567. "Set a field of a MidiEvent"
  568.   `(block nil (ff-call *midiShare* :ptr ,ev :long ,field :long ,val :d0 #x3A)))
  569.  
  570. (defmacro MidiGetField (ev field)
  571. "Get a field of a MidiEvent"
  572.   `(block nil (ff-call *midiShare* :long 0 :ptr ,ev :long ,field :d0 #x3B :long)))
  573.  
  574. (defmacro MidiAddField (ev val)
  575. "Append a field to a MidiEvent (only for sysex and stream)"
  576.   `(block nil (ff-call *midiShare* :ptr ,ev :long ,val :d0 #x1A)))
  577.  
  578. (defmacro MidiCountFields (ev)
  579. "The number of fields of a MidiEvent"
  580.   `(block nil (ff-call *midiShare* :long 0 :ptr ,ev :d0 #x3C :long)))
  581.  
  582.  
  583. ;; To create sequences of MidiShare events
  584.  
  585. (defmacro MidiNewSeq ()
  586. "Allocate an empty sequence"
  587.   `(block nil (ff-call *midiShare* :ptr (%null-ptr) :d0 #x1D :ptr)))
  588.  
  589. (defmacro MidiAddSeq (seq ev)
  590. "Add an event to a sequence"
  591.   `(block nil (ff-call *midiShare* :ptr ,seq :ptr ,ev :d0 #x1E)))
  592.  
  593. (defmacro MidiFreeSeq (seq)
  594. "Free a sequence and its content"
  595.   `(block nil (ff-call *midiShare* :ptr ,seq :d0 #x1F)))
  596.  
  597. (defmacro MidiClearSeq (seq)
  598. "Free only the content of a sequence. The sequence become empty"
  599.   `(block nil (ff-call *midiShare* :ptr ,seq :d0 #x20)))
  600.  
  601. (defmacro MidiApplySeq (seq proc)
  602. "Call a function for every events of a sequence"
  603.   `(block nil (ff-call *midiShare* :ptr ,seq :ptr ,proc :d0 #x21)))
  604.  
  605.  
  606. ;; To send and receive MidiShare events
  607.  
  608. ; To send events
  609.  
  610. (defmacro MidiSendIm (refNum ev)
  611. "send an event now"
  612.   `(block nil (ff-call *midiShare* :word ,refNum :ptr ,ev :d0 #x23)))
  613.  
  614. (defmacro MidiSend (refNum ev)
  615. "send an event using its own date"
  616.   `(block nil (ff-call *midiShare* :word ,refNum :ptr ,ev :d0 #x24)))
  617.  
  618. (defmacro MidiSendAt (refNum ev date)
  619. "send an event at date <date>"
  620.   `(block nil (ff-call *midiShare* :word ,refNum :ptr ,ev :long ,date :d0 #x25)))
  621.  
  622.  
  623. ; To receive events
  624.  
  625. (defmacro MidiCountEvs (refNum)
  626. "Give the number of events waiting in the reception fifo"
  627.   `(block nil (ff-call *midiShare* :long 0 :word ,refNum :d0 #x26 :long)))
  628.  
  629. (defmacro MidiGetEv (refNum)
  630. "Read an event from the reception fifo"
  631.   `(block nil (ff-call *midiShare* :ptr (%null-ptr) :word ,refNum :d0 #x27 :ptr)))
  632.  
  633. (defmacro MidiAvailEv (refNum)
  634. "Get a pointer to the first event in the reception fifo without removing it"
  635.   `(block nil (ff-call *midiShare* :ptr (%null-ptr) :word ,refNum :d0 #x28 :ptr)))
  636.  
  637. (defmacro MidiFlushEvs (refNum)
  638. "Delete all the events waiting in the reception fifo"
  639.   `(block nil (ff-call *midiShare* :word ,refNum :d0 #x29)))
  640.  
  641.  
  642. ; Time Managing and MTC synchronisation
  643.  
  644.  
  645. (defmacro MidiGetTime ()
  646. "give the current time"
  647.   `(block nil (ff-call *midiShare* :long 0 :d0 #x22 :long)))
  648.  
  649. (defmacro MidiGetSyncInfo (syncInfo)
  650. "Fill syncInfo record with current synchronisation informations"
  651.   `(block nil (ff-call *midiShare* :ptr ,syncInfo :d0 #x38)))
  652.  
  653. (defmacro MidiSetSyncMode (mode)
  654. "set the MidiShare synchroniation mode"
  655.   `(block nil (ff-call *midiShare* :word ,mode :d0 #x39)))
  656.  
  657.  
  658. (defmacro MidiGetExtTime ()
  659. "give the current external time"
  660.   `(block nil (ff-call *midiShare* :long 0 :d0 #x3D :long)))
  661.  
  662.  
  663. (defmacro MidiInt2ExtTime (time)
  664. "convert internal time to external time"
  665.   `(block nil (ff-call *midiShare* :long 0 :long ,time :d0 #x3E :long)))
  666.  
  667.  
  668. (defmacro MidiExt2IntTime (time)
  669. "convert external time to internal time"
  670.   `(block nil (ff-call *midiShare* :long 0 :long ,time :d0 #x3F :long)))
  671.  
  672.  
  673. (defmacro MidiTime2Smpte (time format smpteLocation)
  674. "convert a time to an Smpte location using format"
  675.   `(block nil (ff-call *midiShare* :long ,time :short ,format :ptr ,smpteLocation :d0 #x40)))
  676.  
  677.  
  678. (defmacro MidiSmpte2Time (smpteLocation)
  679. "convert an Smpte location to a time"
  680.   `(block nil (ff-call *midiShare* :long 0 :ptr ,smpteLocation :d0 #x41 :long)))
  681.  
  682.  
  683. ;; real-time tasks managing
  684.  
  685. (defmacro MidiCall (proc date refNum arg1 arg2 arg3)
  686. "Call the routine <proc> at date <date> with arguments <arg1> <arg2> <arg3>"
  687.   `(block nil (ff-call *midiShare* :ptr ,proc :long ,date :word ,refNum :long ,arg1 :long ,arg2 :long ,arg3 :d0 #x2C)))
  688.  
  689. (defmacro MidiTask (proc date refNum arg1 arg2 arg3)
  690. "Call the routine <proc> at date <date> with arguments <arg1> <arg2> <arg3>. 
  691.  Return a pointer to the corresponding typeProcess event"
  692.   `(block nil (ff-call *midiShare* :ptr (%null-ptr) :ptr ,proc :long ,date :word ,refNum :long ,arg1 :long ,arg2 :long ,arg3 :d0 #x2D :ptr)))
  693.  
  694. (defmacro MidiDTask (proc date refNum arg1 arg2 arg3)
  695. "Call the routine <proc> at date <date> with arguments <arg1> <arg2> <arg3>. 
  696.  Return a pointer to the corresponding typeDProcess event"
  697.   `(block nil (ff-call *midiShare* :ptr (%null-ptr) :ptr ,proc :long ,date :word ,refNum :long ,arg1 :long ,arg2 :long ,arg3 :d0 #x2E :ptr)))
  698.  
  699. (defmacro MidiForgetTaskHdl (thdl)
  700. "Forget a previously scheduled typeProcess or typeDProcess event created by MidiTask or MidiDTask"
  701.   `(block nil (ff-call *midiShare* :ptr ,thdl :d0 #x2F)))
  702.  
  703. (defmacro MidiForgetTask (ev)
  704. "Forget a previously scheduled typeProcess or typeDProcess event created by MidiTask or MidiDTask"
  705.   `(without-interrupts (rset *taskHdl* :ttaskHdl.task ,ev) (midiforgetTaskHdl *taskHdl*)))
  706.  
  707. (defmacro MidiCountDTasks (refNum)
  708. "Give the number of typeDProcess events waiting"
  709.   `(block nil (ff-call *midiShare* :long 0 :word ,refNum :d0 #x30 :long)))
  710.  
  711. (defmacro MidiFlushDTasks (refNum)
  712. "Remove all the typeDProcess events waiting"
  713.   `(block nil (ff-call *midiShare* :word ,refNum :d0 #x31)))
  714.  
  715. (defmacro MidiExec1DTask (refNum)
  716. "Call the next typeDProcess waiting"
  717.   `(block nil (ff-call *midiShare* :word ,refNum :d0 #x32)))
  718.  
  719.  
  720. ;; special functions
  721.  
  722. ; low level memory managing
  723.  
  724. (defmacro MidiNewCell ()
  725. "Allocate a basic Cell"
  726.   `(block nil (ff-call *midiShare* :ptr (%null-ptr) :d0 #x33 :ptr)))
  727.  
  728. (defmacro MidiFreeCell (cell)
  729. "Delete a basic Cell"
  730.   `(block nil (ff-call *midiShare* :ptr ,cell :d0 #x34)))
  731.  
  732.  
  733. ;;mail boxes
  734.  
  735. (defmacro MidiReadSync (adrMem)
  736. "Read and clear a memory address (not-interruptible)"
  737.   `(block nil (ff-call *midiShare* :ptr (%null-ptr) :ptr ,adrMem :d0 #x2A :ptr)))
  738.  
  739. (defmacro MidiWriteSync (adrMem val)
  740. "write if nil into a memory address (not-interruptible)"
  741.   `(block nil (ff-call *midiShare* :ptr (%null-ptr) :ptr ,adrMem :ptr ,val :d0 #x2B :ptr)))
  742.